home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / Python-1.4 / Docs / Regular_Expressions_3.txt / __headers__.txt next >
Encoding:
Text File  |  1998-06-24  |  2.9 KB  |  51 lines

  1. book described above, it has plenty of examples):
  2.  
  3.  
  4.                                       regex
  5.  
  6. Patterns are specified as strings. Default syntax is emacs-style. 
  7.  
  8. Special Characters (using default syntax): 
  9.  
  10. .       matches any character
  11. *       0 or more of preceeding regular expresssion
  12. +       1 or more of preceeding regular expresssion
  13. ?       0 or 1 of preceeding regular expresssion
  14. [ ]     defines character set: '[a-zA-Z]' to match all letters
  15. [^ ]    defines complemented character set: matches if char is NOT in 
  16. set
  17. ^       matches empty str at beginning of line
  18. $       matches empty str at end of line
  19. \       quoting char: \[ matches char '['
  20. \\      matches '\'; due to Python string rules, write as '\\\\' in        the pattern string.
  21. \|      specifies alternative: 'foo\|bar' matches 'foo' or 'bar'
  22. \( \)   grouping (for \|, or complicated expr, or substr for future        reference by \D character or group() method)
  23. \D      D is digit: matches substr matched by D'th \( \) in pattern
  24. \`      empty str at beginning of file
  25. \'      empty str at end of file
  26. \b      empty str at beg or end of word: '\bis\b' matches 'is', but not 
  27. 'his'
  28. \B      empty str NOT at beginning or end of word
  29. \<      empty str at beginning of word
  30. \>      empty str at end of word
  31. \w      any word constituent
  32. \W      any non-word constituent
  33.  
  34. Variables: 
  35.  
  36. error                   -- Exception when pattern string isn't valid 
  37. regexp.
  38.  
  39. Functions:
  40.  
  41. match(pattern, string)  -- Return how many characters at the beginning                           of <string> match regexp <pattern>                           or -1 if none.
  42.  
  43. search(pattern, string [, pos])                         -- Return the first position in <string> that                           matches regexp <pattern>.  Return -1 if none.                           [starting at <pos>.]
  44.  
  45. compile(pattern [,translate])                        -- Create regexp object that has methods                           match() and search() working as above. Also                           group(i1, [,i2]*). Also regs,  tuple of                            positions matched; regs[0] is whole match,                            next are subexpressions. E.g.                           p = compile('id\([a-z]\)\([a-z]\)')                           p.match('idab') ==> 4                           p.group(1, 2) ==> ('a', 'b')                           p.regs ==> ((0, 4), (2, 3), (3, 4), ...)
  46.  
  47. set_syntax(flag)        -- Set syntax flags for future calls to                           match(), search() and compile(). Returns                           current value. Flags in module regex_syntax.
  48.  
  49. symcomp(pattern [,translate])                        -- Like compile but with symbolic group                           names. Names in angle brackets. Access                            through group method. E.g.                            p = symcomp('id\(<l1>[a-z]\)\(<l2>[a-z]\)')                           p.match('idab') ==> 4                           p.group('l1') ==> 'a'
  50.  
  51.